package rtm.core;

import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import com.google.inject.Inject;

public class CommandFacade {

	@Inject private NetCall netCall;
	@Inject private Parser  parser;
	
	public void call(String url, BaseResponseHandler handler) throws IOException, RtmCallException, SAXException {
		
		final InputStream in = netCall.call(url);
		try {
			parser.parse(in, handler);
		} catch (ParserConfigurationException e) {
			throw new SAXException(e);
		}
		
		if(!handler.isOk()) {
			throw new RtmCallException(handler.getErrorCode(), handler.getErrorMsg());
		}
	}

	/*
	public void run(String method, BaseResponseHandler handler) throws RtmCallException, IOException, SAXException {

		call(urlBuilder.getSigned(method), handler);
		
	}


	public void runWithFrob(String method, String frob, TokenHandler handler) throws IOException, RtmCallException, SAXException {

		call(urlBuilder.getSigned(method, frob), handler);
		
	}


	public void runWithToken(String method, String token, TaskListHandler handler) throws IOException, RtmCallException, SAXException {

		call(urlBuilder.getAuthenticated(method, token), handler);
		
	}
	*/
}
